<template>
  <div>
  <div>
    <center>
      <a class="btn btn-default navbar-btn sign-up" data-sign="signup" data-toggle="modal" @click="add_chapter">添加章节</a>
    <p>
      <label>课程名称：&#12288;&#12288;</label>
      <input v-model="title" type="text">
    </p>
    <p>
      <label>课程描述：&#12288;&#12288;</label>
      <input v-model="desc" type="text">
    </p>

    <p>
      <label>
        课程logo地址：
      </label>
      <input v-model="img_path" type="text">
    </p>

    <p>
      <label>课程类型：&#12288;&#12288;</label>
      <input v-model="course_type" type="text">
    </p>

    <p>
      <label>课程状态：&#12288;&#12288;</label>
      <input v-model="status" type="text">
    </p>
    <p>
      <label>关注人数：&#12288;&#12288;</label>
      <input v-model="follower" type="text">
    </p>

    <p>
      <label>学习人数：&#12288;&#12288;</label>
      <input v-model="learner" type="text">
    </p>
    <p>
      <label>课程标签：&#12288;&#12288;</label>
      <input v-model="tag" type="text">
    </p>

    <p>
        <center><button @click="add_course">添加课程</button></center>
    </p>
    </center>
  </div>
  </div>
</template>

<script>
import {add_post} from '../components/axios_api/api'
export default {
    data(){
        return{
            title: '',
            desc: '',
            img_path: '',
            course_type: '',
            tag: '',
            status: '',
            follower: '',
            learner: '',
            token:'',
        };
    },methods:{
        add_course(){
            var data ={title:this.title,desc:this.desc,img_path:this.img_path,tag:this.tag,course_type:this.course_type,status:this.status,follower:this.follower,learner:this.learner}
            add_post(data).then(resp=>{
            this.token = localStorage.getItem("token")
            console.log('添加成功',resp)
            if(resp.code==200){
            alert('添加成功')
            this.$router.push('/')
            }
            }).catch(err=>{
                console.log(err)
                alert('添加失败')
                this.$router.push('/')
            })
        },
        add_chapter(){
        this.$router.push('/add_chapters')
      }
    }
}
</script>

<style>

</style>